﻿using System.Collections;
using System;
using System.Text;

namespace Triple
{
    public class Triple:IComparable,ICloneable,IEnumerable
    {
        private int a;
        private int b;
        private int c;

        public Triple(int a, int b, int c)
        {
            this.a = a;
            this.b = b;
            this.c = c;
        }

        public int this[int index] 
        {
            get
            {
                switch (index) 
                {
                    case 0:
                        return this.A;
                    case 1:
                        return this.B;
                    case 2:
                        return this.C;
                    default:
                        throw new ArgumentOutOfRangeException("Invalid index");
                
                }
                
            }

            set 
            {
               
                switch (index)
                {
                    case 0:
                        this.A = value;
                        break;
                    case 1:
                        this.B = value;
                        break;
                    case 2:
                        this.C = value;
                        break;
                    default:
                        throw new ArgumentOutOfRangeException("Invalid index");
                }
                
            }
        }

        public IEnumerator GetEnumerator()
        {
            for (int i = 0; i < 3; i++) 
            {
                yield return this[i];
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
           return this.GetEnumerator();
        }

        public int A
        {
            get
            {
                return a;
            }
            set
            {
                a = value;
            }
        }

        public int B
        {
            get
            {
                return b;
            }
            set
            {
                b = value;
            }
        }

        public int C
        {
            get
            {
                return c;
            }
            set
            {
                c = value;
            }
        }

        public static Triple operator +(Triple firstNumber, Triple secondNumber)
        {
            int a = firstNumber.A + secondNumber.A;
            int b = firstNumber.B + secondNumber.B;
            int c = firstNumber.C + secondNumber.C;

            return new Triple(a, b, c);
        }

        public static Triple operator -(Triple firstNumber, Triple secondNumber) 
        {
            int a = firstNumber.A - secondNumber.A;
            int b = firstNumber.B - secondNumber.B;
            int c = firstNumber.C - secondNumber.C;

            return new Triple(a, b, c);
        }

        public static Triple operator ++(Triple firstNumber) 
        {
            return new Triple(firstNumber.A++, firstNumber.B++, firstNumber.C++);
        }

        public static bool operator == (Triple firstNumber, Triple secondNumber)
        {
            return firstNumber.Equals(secondNumber);
        }

        public static bool operator !=(Triple firstNumber, Triple secondNumber)
        {
            return !firstNumber.Equals(secondNumber);
        }

        public override bool  Equals(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("You cant compare null");
            }
            Triple otherTriple = obj as Triple;
            return (this.A == otherTriple.A) && (this.B == otherTriple.B) &&
                (this.C == otherTriple.C);
        }

        public override string ToString()
        {
            return String.Format("{0} {1} {2}", this.a, this.B, this.C);
        }

        public object Clone()
        {
            return new Triple(this.A, this.B, this.C);
        }

        public int CompareTo(object obj)
        {
            if (obj == null) 
            {
                throw new ArgumentNullException("You cant compare null");
            }
            Triple otherTriple = obj as Triple;
            int sum = this.A + this.B + this.C;
            int otherSum = otherTriple.A + otherTriple.B + otherTriple.C;

            return sum.CompareTo(otherSum);
        }
    }
}
